<style>
<!--
#myform th{border:1px solid #ccc;text-align:center;}
#myform td{border:1px solid #ccc;text-align:center;}
-->
</style>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\models\SysItem;
use backend\models\GrpClass;


$this->registerCss('
	
	.table tbody td{
		text-align:center;
	}
');
/* @var $this yii\web\View */
/* @var $model backend\models\Taozhuang */
/* @var $form yii\widgets\ActiveForm */
//var_dump($model_pos);

$app_if_return = [
''=>'',
'0' => '编辑',
'1' => '上架',
'2' => '下架',
'3' => '删除',
];

echo "<table id='myform'>";
echo "<tr>
		<th>单品ID</th>
		<th>名称</th>
		<th>单品图</th>
		<th>类目名</th>
		<th>厂家编码</th>
		<th>状态</th>
		<th>单价</th>
		<th>可售</th>
	 </tr>";
foreach ($model_pos as $key => $value) {
	//echo  $value['item_id'].',';
	$one_sysitem = SysItem::find_sysitem_info($value['item_id']);
	
	echo "<tr>";
	echo "<td>".$value['item_id'].'</td>';
	echo "<td>".$one_sysitem['name'].'</td>';
	echo "<td><img style='max-width:80px;max-height:80px;' src='".$value['small_img']."'></td>";
	echo "<td>".$one_sysitem['class_id'].GrpClass::find_class_name($one_sysitem['class_id']).'</td>';
	echo "<td>".$one_sysitem['factory_code'].'</td>';
	echo "<td>".$app_if_return[$one_sysitem['app_return']].'</td>';
	echo "<td>".$one_sysitem['price_base'].'</td>';
	echo "<td><select id=pos_".$value['id']." onchange='change_status(".$value['id'].",".$value['item_id'].",".$value['tzid'].")'>";
	echo $value['pay_state']==0?"<option selected='selected' value='0'>非卖品</option>":"<option value='0'>非卖品</option>"; 
	echo $value['pay_state']==1?"<option selected='selected' value='1'>销售品</option>":"<option value='1'>销售品</option>";
	echo $value['pay_state']==2?"<option selected='selected' value='2'>赠品</option>":"<option value='2'>赠品</option>";
	echo	"</select></td>";
	echo "</tr>";
	
}
echo "</table>";
?>
<!--  
<div class="taozhuang-form">

    
</div>
-->
<script type="text/javascript">
function change_status(pos_id,item_id,tzid){
	//alert(item_id);
	var pay_state = $("#pos_"+pos_id).val();
	//alert(pay_state);
	//alert(item_id);
//	alert(tzid);
		$.ajax({
			url:"index.php?r=taozhuang/tzpos-item-pay&item_id="+item_id+"&tzid="+tzid+"&pay_state="+pay_state,
			data:{},
			//dataType:"json",
			success:function(data){
			if(data){
				alert('已更改');
				}
			//	window.location.reload();
			},	
	        error: function(){
	           
	              alert("Error!");
	            }
		});
	
}
</script>
